		TITLE	INSTALL_PENT - Copyright (C) 1994 SLR Systems

		INCLUDE	MACROS
		INCLUDE	SEGMSYMS

if	fg_segm

		PUBLIC	INSTALL_PENT


		.DATA

		EXTERNDEF	LATEST_PENT_GINDEX:DWORD,FIRST_PENT_GINDEX:DWORD,LAST_PENT_GINDEX:DWORD

		EXTERNDEF	PENT_GARRAY:STD_PTR_S,PENT_STUFF:ALLOCS_STRUCT


		.CODE	PASS1_TEXT

		EXTERNDEF	COMMON_INST_INIT:PROC,PENT_POOL_GET:PROC


INIT_PENT	PROC
		;
		;
		;
		PUSHM	EDX,ECX,EAX
		MOV	EAX,OFF PENT_STUFF

		CALL	COMMON_INST_INIT

		POPM	EAX,ECX,EDX,EDI,ESI
;		JMP	INSTALL_PENT

INIT_PENT	ENDP


INSTALL_PENT	PROC
		;
		;EDX:EAX:ECX IS ITEM TO STORE...
		;
		PUSH	ESI
		MOV	ESI,PENT_STUFF.ALLO_HASH_TABLE_PTR

		PUSH	EDI
		TEST	ESI,ESI

		MOV	EDI,EDX			;SAVE GINDEX IN EDI
		JZ	INIT_PENT
		;
		;EDX	IS GINDEX
		;EAX	IS OFFSET FROM ABOVE
		;CL	IS TYPE, 0=SEG, 1=SYM, 2=GROUP
		;
		;CALCULATE A USABLE HASH
		;
		ROL	EDX,16
		PUSH	EBX

		AND	ECX,07FH
		MOV	EBX,EAX			;SAVE OFFSET IN EBX

		XOR	EAX,EDX
		MOV	EDX,ECX

		DIV	PENT_STUFF.ALLO_HASH

		PUSH	EBP
		MOV	EBP,ECX

		MOV	EAX,[ESI+EDX*4]
		LEA	ESI,[ESI+EDX*4 - PENT_STRUCT._PENT_NEXT_HASH_GINDEX]
NAME_NEXT:
		;
		;EDI IS GINDEX
		;EBX IS OFFSET
		;EBP IS TYPE
		;
		TEST	EAX,EAX
		JZ	DO1

		MOV	EDX,EAX
		CONVERT	EAX,EAX,PENT_GARRAY
		MOV	ESI,EAX
		ASSUME	EAX:PTR PENT_STRUCT,ESI:PTR PENT_STRUCT
		;
		;IS IT A MATCH?
		;
		MOV	ECX,[EAX]._PENT_SEGM_GINDEX
		MOV	EAX,[EAX]._PENT_NEXT_HASH_GINDEX

		CMP	ECX,EDI
		JNZ	NAME_NEXT

		CMP	EBX,[ESI]._PENT_OFFSET
		JNZ	NAME_NEXT
		;
		;TYPE MUST MATCH TOO, DON'T BOTHER CHECKING
		;
		MOV	ECX,[ESI]._PENT_REF_COUNT
		MOV	EAX,EDX

		INC	ECX
		MOV	LATEST_PENT_GINDEX,EAX

		POPM	EBP,EBX

		POP	EDI
		MOV	[ESI]._PENT_REF_COUNT,ECX

		POP	ESI

		RET

DO1:
		;
		;ESI GETS POINTER
		;
		;EDI IS GINDEX
		;EBX IS OFFSET
		;EBP IS TYPE
		;
		MOV	EAX,SIZE PENT_STRUCT
		CALL	PENT_POOL_GET		;ES:DI AX

		MOV	EDX,LAST_PENT_GINDEX
		MOV	ECX,EAX
		ASSUME	ECX:PTR PENT_STRUCT
		INSTALL_POINTER_GINDEX	PENT_GARRAY

		MOV	[ESI]._PENT_NEXT_HASH_GINDEX,EAX
		MOV	LAST_PENT_GINDEX,EAX

;		TEST	EDX,EDX
;		JZ	FIRST_PENT

;		CONVERT	EDX,EDX,PENT_GARRAY
;		ASSUME	EDX:PTR PENT_STRUCT

		MOV	[ECX]._PENT_NEXT_GINDEX,EDX
;FP_RET:
		XOR	ESI,ESI

		ROR	EBP,2
;		MOV	[ECX]._PENT_NEXT_GINDEX,ESI

		INC	EBP
		MOV	[ECX]._PENT_SEGM_GINDEX,EDI

		MOV	[ECX]._PENT_REF_COUNT,EBP		;COUNT=1
		POP	EBP

		MOV	[ECX]._PENT_NEXT_HASH_GINDEX,ESI
		MOV	[ECX]._PENT_OFFSET,EBX

		POPM	EBX,EDI

		MOV	LATEST_PENT_GINDEX,EAX
		POP	ESI

		RET

;FIRST_PENT:
;		MOV	FIRST_PENT_GINDEX,EAX
;		JMP	FP_RET

INSTALL_PENT	ENDP

endif

		END

